<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 数组去重 id相同  可以多个方法实现
      let arr = [
        { id: 1, name: '张三', age: 18 },
        { id: 2, name: '李四', age: 20 },
        { id: 3, name: '王五', age: 15 },
        { id: 1, name: '张三', age: 18 },
        { id: 4, name: '王五', age: 19 },
      ]
      // let arr1 = {}
      // let arr2 = []
      // for(let i = 0; i < arr.length; i++){
      //   arr1[arr[i]['id']]=arr[i]
      // }
      // console.log(arr1);
      // for(let k in arr1)
      //   arr2.push(arr1[k])
      // }
      // console.log(arr2);




      // let arr1 = []
      // arr.forEach((item) => {
      //   let flag = true
      //   arr1.forEach((element) => {
      //     if (item.id === element.id) {
      //       flag = false
      //     }
      //   })
      //   if (flag) {
      //     arr1.push(item)
      //   }
      // })
      // console.log(arr1)



    </script>
  </body>
</html>
